package dto

import (
	"ginfast/api/mall/model"
	"ginfast/pkg/orm"
)

type Where struct {
	*orm.DbPage
	OrderSn         string `form:"orderSn"`
	ReceiverKeyword string `form:"receiverKeyword"`
	OrderType       string `form:"orderType"`
	SourceType      string `form:"sourceType"` //
	Status          string `form:"status"`
	Phonenumber     string `form:"phonenumber"` // 手机号
	PayType         string `form:"payType"`     //
}

func (o *Where) DbModelWhere(v interface{}, handles ...func(dw *orm.DbWhere)) *orm.DbWhere {
	w := o.DbWhere()
	switch v.(type) {
	case *model.Order:
		if o.ReceiverKeyword != "" {
			w.Add("receiver_name like ? or receiver_phone like ?", o.ReceiverKeyword, o.ReceiverKeyword)
		}
		w.Like("order_sn", o.OrderSn)
		w.EqualNumber("source_type", o.SourceType)
		w.EqualNumber("order_type", o.OrderType)
		w.EqualNumber("status", o.Status)
	case *model.User:
		w.Like("phonenumber", o.Phonenumber)
	case *model.Consumption:
		w.EqualNumber("pay_type", o.PayType)
	}
	for _, hle := range handles {
		hle(w)
	}
	return w.Model(v)
}
